﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace huaguwang.hgmanage.soft
{
      public partial class softcomment : PageBaseAdmin
      {
            private readonly D_T_SoftWareEvaluating_Exp m_dal = new D_T_SoftWareEvaluating_Exp();
            protected void Page_Load(object sender, EventArgs e)
            {
                  Pager.PageSize = 10;
                  this.WebUserToolBar1.MainInit
                  (
                        UserConst.Exp_GetUser,
                        UserConst.Exp_GetButtonList,
                        (i, but) =>
                        {
                              switch (i)
                              {
                                    case 1:
                                          but.Attributes.Add("onclick", "return GetUpdateCheckDefault();");
                                          break;
                                    case 2:
                                          but.Attributes.Add("onclick", "return GetDelCheckDefault();");
                                          break;
                                    default:
                                          break;
                              }
                        },
                        UserConst.Exp_ToolBarErr,
                        new huaguwang.WebControls.WebUserToolBar.SelectItem()
                        {
                              FuncGetText = () => TextBox1.Text.Trim(),
                              FuncSetText = v => { TextBox1.Text = v; },
                              Name = TextBox1.ID
                        },
                      new huaguwang.WebControls.WebUserToolBar.SelectItem()
                      {
                            FuncGetText = () => TextBox2.Text.Trim(),
                            FuncSetText = v => { TextBox2.Text = v; },
                            Name = TextBox2.ID
                      }
                  );

                  if (!this.IsPostBack)
                  {
                        SetData(0);
                  }
            }

            private void SetData(int begin)
            {
                  var txtSoftWareName = this.WebUserToolBar1.MainGetQuery(this.TextBox1.ID);
                  var txtSoftWareCommendTitle = this.WebUserToolBar1.MainGetQuery(this.TextBox2.ID);
                  var count = 0;
                  this.Repeater1.DataSource = m_dal.GetSoftWareCommentList(begin, Pager.PageSize, txtSoftWareName, txtSoftWareCommendTitle, ref count);
                  this.Repeater1.DataBind();
                  Pager.RecordCount = count;
            }

            protected void WebUserToolBar1_Button0(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        var sKey = WebUserToolBar1.MainSetSKey();
                        Response.Redirect("softcomment_e.aspx?" + sKey, false);
                  });
            }

            protected void WebUserToolBar1_Button1(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        var strID = Request.Params["HiddenID"].Exp_Trim();
                        var sKey = WebUserToolBar1.MainSetSKey();
                        Response.Redirect("softcomment_e.aspx?ID=" + strID + "&" + sKey, false);
                  });
            }

            protected void WebUserToolBar1_Button2(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        var strID = Request.Params["HiddenID"].Exp_Trim();
                        var intA = strID.Exp_SplitToList(',', Sel => Sel.Exp_IntTryParse()).Where(Sel => Sel > 0).ToList();
                        if (intA == null || intA.Count <= 0)
                        {
                              this.Exp_PageAlter("没有找到可以删除的信息");
                              return;
                        }

                        int i = 0;
                        foreach (var item in intA)
                        {
                              i++;
                        }


                        var refInt = m_dal.UpdateFlag(intA);
                        if (refInt > 0)
                        {
                              this.Exp_PageWriteLog(Log_Type.delete, "软件评测资料", intA);
                              SetData(0);
                              this.Exp_PageAlter("删除操作成功");
                              return;
                        }
                        else
                        {
                              this.Exp_PageAlter("删除操作失败");
                              return;
                        }
                  });
            }

            protected void WebUserToolBar1_Button3(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        WebUserToolBar1.MainSetQuery();
                        SetData(0);
                  });
            }

            /// <summary>
            /// 分页控件的页面事件
            /// </summary>
            protected void Pager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
            {
                  SetData((e.NewPageIndex - 1) * Pager.PageSize);
            }
      }
}
